#include <X11/XF86keysym.h>
/* See LICENSE file for copyright and license details. */

/* appearance */
static const unsigned int borderpx = 2; /* border pixel of WIN */
static const unsigned int snap = 32;    /* snap pixel */
static const unsigned int systraypinning =
    0; /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor
          X */
static const unsigned int systrayonleft =
    0; /* 0: systray in the right corner, >0: systray on left of status text */
static const unsigned int systrayspacing = 2; /* systray spacing */
static const int systraypinningfailfirst =
    1; /* 1: if pinning fails, display systray on the first monitor, False:
          display systray on the last monitor*/
static const unsigned int panel[] = {0, 0, 0, 0};//positions: 0-top panel, 1-bottom panel, 2-left panel, 3-right panel
static const int showsystray = 1;   /* 0 means no systray */
static const int showbar = 1;       /* 0 means no bar */
static const int topbar = 0;        /* 0 means bottom bar */
static const Bool viewontag = False; /* Switch view on tag switch */
static const char *fonts[] = {
    "Cousine Nerd Font Mono:pixelsize=18:antialias=true:autohint=true"};
// static const char *fonts[]          = { "SauceCodePro Nerd Font:size=10" };
static const char col_white[] = "#FFFFFF";
static const char col_black[] = "#000000";
static const char col_gray1[] = "#222222";
static const char col_gray2[] = "#444444";
static const char col_gray3[] = "#bbbbbb";
static const char col_gray4[] = "#eeeeee";
static const char col_cyan[] = "#005577";
static const char col_blue[] = "#000066";
static const char col_yellow[] = "#FFFF00";
static const char *colors[][3] = {
    /*                   fg         bg         border   */
    // [SchemeNorm]     = { col_gray3, col_gray1, col_gray2 },
    [SchemeNorm] = {col_gray3, col_black, col_black},
    // [SchemeSel] = {col_black, col_white, col_white},
    [SchemeSel] = {col_black, col_white, col_yellow},
    [SchemeHid] = {col_black, col_gray3, col_cyan},
    // Statusbar right {text,background,not used but cannot be empty}
    [SchemeStatus] = {col_white, col_black, col_black},
    // Tagbar left selected {text,background,not used but cannot be empty}
    [SchemeTagsSel] = {col_white, col_cyan, col_black},
    // Tagbar left unselected {text,background,not used but cannot be empty}
    [SchemeTagsNorm] = {col_white, col_black, col_black},
    // infobar middle  selected {text,background,not used but cannot be empty}
    [SchemeInfoSel] = {col_black, col_white, col_black},
    // infobar middle  unselected {text,background,not used but cannot be empty}
    [SchemeInfoNorm] = {col_black, col_white, col_black},
};

/* tagging */
static const char *tags[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};

static const Rule rules[] = {
    /* xprop(1):
     *	WM_CLASS(STRING) = instance, class
     *	WM_NAME(STRING) = title
     */
    /* class      instance    title       tags mask     isfloating   monitor */
    // { "<<>>",     <<>>,       <<>>,       <<>>,         <<>>,          -1 },
    {"Gimp", NULL, NULL, 0, 1, -1},
    {"Firefox", NULL, NULL, 1 << 8, 0, -1},
    {"VirtualBox Manager", NULL, "VirtualBox", 1 << 2, 0, -1},
    // {"Pcmanfm", NULL, "Pcmanfm", 0, 1, -1},
    {"feh", NULL, NULL, 0, 1, -1},
    // { "Chromium", NULL,      "Chromium",  1 << 1,       0,           -1 },
    {"lxqt-openssh-askpass", NULL, NULL, 0, 1, -1},
};

/* layout(s) */
static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
static const int nmaster = 1;    /* number of clients in master area */
static const int resizehints =
    0; /* 1 means respect size hints in tiled resizals */

static const Layout layouts[] = {
    /* symbol     arrange function */
    {"[]=", tile}, /* first entry is default */
    {"><>", NULL}, /* no layout function means floating behavior */
    {"[M]", monocle},
};

/* key definitions */
#define ALT Mod1Mask
// #define MODKEYR Mod5Mask
#define WIN Mod4Mask
#define TAGKEYS(KEY, TAG)                                                      \
  {ALT, KEY, view, {.ui = 1 << TAG}},                                       \
      {ALT|ControlMask,KEY, toggleview, {.ui = 1 << TAG}},               \
      {ALT|ShiftMask,KEY, tag, {.ui = 1 << TAG}},                        \
      {ALT|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG}},
#define STACKKEYS(MOD,ACTION) \
	{ MOD, XK_Tab, ACTION##stack, {.i = PREVSEL } }, \
	{ MOD,	XK_j,	ACTION##stack,	{.i = INC(+1) } }, \
	{ MOD,	XK_k,	ACTION##stack,	{.i = INC(-1) } },
	/*
    { MOD,  XK_v,   ACTION##stack,  {.i = 0 } }, \
	{ MOD, XK_a,     ACTION##stack, {.i = 1 } }, \
	{ MOD, XK_z,     ACTION##stack, {.i = 2 } }, \
	{ MOD, XK_x,     ACTION##stack, {.i = -1 } },
    */
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
#define SHCMD(cmd)                                                             \
  {                                                                            \
    .v = (const char *[]) { "/bin/sh", "-c", cmd, NULL }                       \
  }

/* commands */

static const char *openmenu[] = {"/home/tan/.local/bin/openthe","menu", NULL};
static const char *openterm[] = {"/home/tan/.local/bin/openthe","terminal", NULL};
static const char scratchpadname[] = "scratchpad";
/*static const char *openscratchpad[] = {"st", "-t", scratchpadname, "-g", "70x21", NULL};*/
static const char *openscratchpad[] = {"kitty", "--title", scratchpadname, "--override", "initial_window_width=1120", "--override", "initial_window_height=653", "--override", "remember_window_size=no", NULL };
static const char *openbrowser[] = {"/home/tan/.local/bin/openthe","browser", NULL};
static const char *opensun[] = {"/home/tan/.local/bin/openthe","sun", NULL};
static const char *killsun[] = {"/home/tan/.local/bin/killthe","sun", NULL};
static const char *opentodesk[] = {"/home/tan/.local/bin/openthe","todesk", NULL};
static const char *killtodesk[] = {"/home/tan/.local/bin/killthe","todesk", NULL};
static const char *opendictionary[] = {"/home/tan/.local/bin/openthe","dictionary", NULL};
// statsdfic const char *openblueman[] = {"/home/tan/.local/bin/openthe","blueman-manager", NULL};
static const char *opensharing[] = {"/home/tan/.local/bin/openthe","sharing", NULL};
static const char *openkeepassx[] = {"/home/tan/.local/bin/openthe","keepassx", NULL};
static const char *openoffice[] = {"/home/tan/.local/bin/openthe","office", NULL};
static const char *openscreenshot0[] = {"/home/tan/.local/bin/openthe","screenshot-noclip",NULL};
static const char *openscreenshot1[] = {"/home/tan/.local/bin/openthe","screenshot-clip",NULL};
static const char *openfilemanager[] = {"/home/tan/.local/bin/openthe","filemanager", NULL};
static const char *opentip[] = {"/home/tan/.local/bin/openthe","tip", NULL};
static const char *openscreenkey[] = {"/home/tan/.local/bin/openthe","screenkey", NULL};
static const char *openqq[] = {"/home/tan/.local/bin/openthe","qq", NULL};
static const char *openwechat[] = {"/home/tan/.local/bin/openthe","wechat", NULL};
// static const char *openladder[] = {"/home/tan/.local/bin/openthe","ladder", NULL};

// keybindings for brightness
static const char *brightencmd[] = {"brightnessctl", "set", "+10%", NULL};
static const char *darkencmd[] = {"brightnessctl", "set", "10%-", NULL};

static const char *suspend[] = {"/home/tan/.local/bin/suspend.sh", NULL};

// execute some scripts
static const char *volup[] = {"/home/tan/.local/bin/set-volume", "1", NULL};
static const char *voldown[] = {"/home/tan/.local/bin/set-volume", "-1", NULL};
static const char *voltoggle[] = {"/home/tan/.local/bin/set-volume", "0", NULL};
// static const char *mapkeycmd[]  = { "/home/tan/.local/bin/keymap-qwerty",
// NULL };
/*static const char *dmenuemoji[] = {"/home/tan/.local/bin/dmenu-emoji", NULL};*/
static const char *wallpaper[] = {"/home/tan/.local/bin/change-wallpaper", NULL};
//static const char *wubilookup[] = {"/home/tan/.local/bin/wubilookup", NULL};
static const char *togglenumlock[] = {"/home/tan/.local/bin/numlock.sh", NULL};

#include "movestack.c"
#include "focusurgent.c"
static Key keys[] = {
    /* modifier               key        function        argument */
    // for dwm-setborderpx begin
	{ ALT|ShiftMask,             XK_s, 		setborderpx,    {.i = -1 } },
	{ ALT|ShiftMask,             XK_a, 		setborderpx,    {.i = +1 } },
	{ ALT|ShiftMask,             XK_z, 	setborderpx,    {.i = 0 } },
    // for dwm-setborderpx end
    // for dwm-awesomebar
    // {ALT|ControlMask,           XK_j,            focusstackhid, {.i = +1}},
    // {ALT|ControlMask,           XK_k,            focusstackhid, {.i = -1}},
    // {ALT,                       XK_j,            focusstackvis, {.i = +1}},
    // {ALT,                       XK_k,            focusstackvis, {.i = -1}},
	STACKKEYS(ALT,                          focus)
	STACKKEYS(ALT|ShiftMask,                push)
    // {ALT|ControlMask,           XK_equal,        show, {0}}, // 取消当前窗口的隐藏状态
    // {ALT,                       XK_minus,        hide, {0}},
    // for dwm-moveresize
    {ALT,                       XK_Down,         moveresize,     {.v = "0x 25y 0w 0h"}},
    {ALT,                       XK_Up,           moveresize,     {.v = "0x -25y 0w 0h"}},
    {ALT,                       XK_Right,        moveresize,     {.v = "25x 0y 0w 0h"}},
    {ALT,                       XK_Left,         moveresize,     {.v = "-25x 0y 0w 0h"}},
    {ALT|ShiftMask,             XK_Down,         moveresize,     {.v = "0x 0y 0w 25h"}},
    {ALT|ShiftMask,             XK_Up,           moveresize,     {.v = "0x 0y 0w -25h"}},
    {ALT|ShiftMask,             XK_Right,        moveresize,     {.v = "0x 0y 25w 0h"}},
    {ALT|ShiftMask,             XK_Left,         moveresize,     {.v = "0x 0y -25w 0h"}},
    // hide to top right corner
    {ALT|ControlMask,           XK_BackSpace,    moveresize,     {.v = "-1x -1y 0w 0h"}},
    // centerize
    {ALT|ControlMask,           XK_space,        moveresize,     {.v = "-2x -2y 0w 0h"}},
    {ALT|ControlMask,           XK_Up,           moveresizeedge, {.v = "t"}},
    {ALT|ControlMask,           XK_Down,         moveresizeedge, {.v = "b"}},
    {ALT|ControlMask,           XK_Left,         moveresizeedge, {.v = "l"}},
    {ALT|ControlMask,           XK_Right,        moveresizeedge, {.v = "r"}},
    {ALT|ControlMask|ShiftMask, XK_Up,           moveresizeedge, {.v = "T"}},
    {ALT|ControlMask|ShiftMask, XK_Down,         moveresizeedge, {.v = "B"}},
    {ALT|ControlMask|ShiftMask, XK_Left,         moveresizeedge, {.v = "L"}},
    {ALT|ControlMask|ShiftMask, XK_Right,        moveresizeedge, {.v = "R"}},
    // for dwm-movestack
    {ALT|ShiftMask,             XK_j,            movestack,      {.i = +1}},
    {ALT|ShiftMask,             XK_k,            movestack,      {.i = -1}},
    // for dwm-canfocusfloating
    {ALT,                       XK_s,togglecanfocusfloating,     {0}},
    // for dwm-cfacts
    {ALT|ControlMask,           XK_equal,        setcfact,       {.f = +0.25}},
    {ALT|ControlMask,           XK_minus,        setcfact,       {.f = -0.25}},
    {ALT|ControlMask|ShiftMask, XK_equal,        setcfact,       {.f = 0.00}},
    // for dwm-scratchpad
    {ALT,               XK_n,    togglescratch,      {.v = openscratchpad}},
    {ALT,               XK_d,            spawn,      {.v = openmenu}},
    {ALT,               XK_e,            spawn,      {.v = togglenumlock}},
    // {WIN,              XK_m,            spawn,      {.v = dmenuemoji}},
    {ALT,               XK_x,            spawn,      {.v = opentip}},
    {WIN,              XK_w,            spawn,      {.v = wallpaper}},
    {WIN,              XK_b,            spawn,      {.v = opensharing}},
    {WIN,              XK_c,            spawn,      {.v = openoffice}},
    {WIN,              XK_s,            spawn,      {.v = opensun}},
    {WIN|ShiftMask,    XK_s,            spawn,      {.v = killsun}},
    {WIN,              XK_t,            spawn,      {.v = opentodesk}},
    {WIN|ShiftMask,    XK_t,            spawn,      {.v = killtodesk}},
    {WIN,              XK_space,        spawn,      {.v = opendictionary}},
    {WIN,              XK_x,            spawn,      {.v = openbrowser}},
    {WIN,              XK_z,            spawn,      {.v = openterm}},
    {WIN,              XK_r,            spawn,      {.v = openscreenkey}},
    {WIN,              XK_p,            spawn,      {.v = openkeepassx}},
    {WIN,              XK_e,            spawn,      {.v = openfilemanager}},
    {WIN,              XK_q,            spawn,      {.v = openqq}},
    {WIN,              XK_a,            spawn,      {.v = openwechat}},
    // {WIN,           XK_d,            spawn,      {.v = openladder}},
    //{WIN,              XK_l,            spawn,      {.v = wubilookup}},
    {0,        XF86XK_MonBrightnessDown,    spawn,      {.v = darkencmd}},
    {0,        XF86XK_MonBrightnessUp,      spawn,      {.v = brightencmd}},
    {0,        XF86XK_AudioLowerVolume,     spawn,      {.v = voldown}},
    {0,        XF86XK_AudioMute,            spawn,      {.v = voltoggle}},
    {0,        XF86XK_AudioRaiseVolume,     spawn,      {.v = volup}},
    {0,        XF86XK_Suspend,              spawn,      {.v = suspend}},
    {0,                    0xff61,          spawn,      {.v = openscreenshot1}},
    {ShiftMask,            0xff61,          spawn,      {.v = openscreenshot0}},
    {ALT|ShiftMask,     XK_q,            quit,     {}},
    {ALT,               XK_b,            togglebar,  {0}},
    {ALT,               XK_i,            incnmaster, {.i = +1}},
    {ALT,               XK_o,            incnmaster, {.i = -1}},
    {ALT,               XK_h,            setmfact,   {.f = -0.05}},
    {ALT,               XK_l,            setmfact,   {.f = +0.05}},
    {ALT,               XK_Return,       zoom,       {0}},
    // Alt+Escape for previous tag
    {ALT,               0xff1b,   view,       {0}},
    {ALT,               XK_v,            killclient, {0}},
    // {MODKEYR,              XK_v,            killclient, {0}},
    {ALT,               XK_t,            setlayout,  {.v = &layouts[0]}},
    {ALT,               XK_f,            setlayout,  {.v = &layouts[1]}},
    {ALT,               XK_m,            setlayout,  {.v = &layouts[2]}},
    // { ALT,              XK_space,  setlayout,      {0} },
    {ALT|ShiftMask,     XK_space,        togglefloating, {0}},
    {ALT,               XK_0,            view,       {.ui = ~0}},
    {ALT|ShiftMask,     XK_0,            tag,        {.ui = ~0}},
    {ALT,               XK_comma,        focusmon,   {.i = -1}},
    {ALT,               XK_period,       focusmon,   {.i = +1}},
    {ALT|ShiftMask,     XK_comma,        tagmon,     {.i = -1}},
    {ALT|ShiftMask,     XK_period,       tagmon,     {.i = +1}},
   	{ALT,               XK_u,            focusurgent,    {0} },
    TAGKEYS(XK_1, 0) TAGKEYS(XK_2, 1) TAGKEYS(XK_3, 2) TAGKEYS(XK_4, 3)
    TAGKEYS(XK_5, 4) TAGKEYS(XK_6, 5) TAGKEYS(XK_7, 6) TAGKEYS(XK_8, 7)
    TAGKEYS(XK_9, 8)};

/* button definitions */
/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
 * ClkClientWin, or ClkRootWin */
static Button buttons[] = {
    /* click                event mask      button          function argument
     */
    {ClkLtSymbol,              0,           Button1,        setlayout,      {0}},
    {ClkLtSymbol,              0,           Button3,        setlayout,      {.v = &layouts[2]}},
    {ClkWinTitle,              0,           Button2,        togglewin,      {0}},
    {ClkWinTitle,              0,           Button1,        zoom,           {0}},
    {ClkStatusText,            0,           Button2,        spawn,          {.v = openterm}},
    {ClkClientWin,             ALT,      Button1,        movemouse,      {0}},
    {ClkClientWin,             ALT,      Button2,        togglefloating, {0}},
    {ClkClientWin,             ALT,      Button3,        resizemouse,    {0}},
    {ClkTagBar,                0,           Button1,        view,           {0}},
    {ClkTagBar,                0,           Button3,        toggleview,     {0}},
    {ClkTagBar,                ALT,      Button1,        tag,            {0}},
    {ClkTagBar,                ALT,      Button3,        toggletag,      {0}},
};
